package br.com.spread.svnutils.converters;

import java.util.ArrayList;
import java.util.List;

import br.com.spread.svnutils.Path;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

public class PathConverter implements Converter {
	public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
		List<Path> paths = new ArrayList<Path>();
		
		while (reader.hasMoreChildren()){
			reader.moveDown();
			paths.add(new Path(reader.getAttribute("kind"), reader.getAttribute("action"), reader.getValue().trim()));
			reader.moveUp();
		}
		
		return paths;
	}

	public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
		System.out.println();
	}

	public boolean canConvert(Class type) {
		return type.equals(ArrayList.class);
	}
}
